package com.zhangxiaofanfan.hotcode.second;


/**
 * <a href="https://leetcode.cn/problems/search-in-rotated-sorted-array/description/?envType=study-plan-v2&envId=top-100-liked">33. 搜索旋转排序数组</a>
 *
 * @date 2024-06-29 03:21:25
 * @author zhangxiaofanfan
 */
public class HotCode067 {
    public static void main(String[] args) {
        HotCode067 hotCode = new HotCode067();
        int[] nums = {4, 5, 6, 7};
        System.out.println(hotCode.findMin(nums));
    }

    public int findMin(int[] nums) {
        if (nums.length == 1 || nums[0] < nums[nums.length - 1]) {
            return nums[0];
        }
        int left = 0, right = nums.length - 1, mid;
        while (left < right) {
            mid = left + ((right - left) >> 1);
            if (nums[mid] < nums[right]) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return nums[left];
    }
}
